//
//  CustomXibView.m
//  xibDemo
//
//  Created by wanglei on 17/2/4.
//  Copyright © 2017年 wanglei. All rights reserved.
//

#import "CustomXibView.h"

@interface CustomXibView ()

@end

@implementation CustomXibView

// 代码加载调用
- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUi];
    }
    return self;
}


// xib调用方法
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setUpUi];
    }
    return self;
}


- (void)setUpUi{
    
    [[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
    [self addSubview:self.myView];
}


- (void)drawRect:(CGRect)rect{
    // 这里的位置约束会相对于CustomXibView进行布局,不管是xib加载还是纯代码加载都会经过这个方法
    self.myView.frame = CGRectMake(40, 100, 300, 240);
}

@end
